#ifndef     __DRAW_TASK_H
#define     __DRAW_TASK_H

#include "../rtos/thread.h"
#include "../rtos/message_queue.h"
#include "../utils/object.h"

namespace task {

class DrawTask : public rtos::Thread<DrawTask, 1024, osPriorityHigh2> {

public:

    enum class State : uint8_t {
        WORK = 0,
        IDLE = 1,
        STOP = 2,
        TIMEOUT = 3,
        DRAW_OUTLET = 4,
    };
    
    void run();

    void stop() { m_mq.post(State::STOP); }
    void reset() { m_mq.post(State::IDLE); }

    inline uint8_t state() { return static_cast<uint8_t>(m_state); }

private:
    bool await(uint32_t timeout = osWaitForever);

    void do_work();
    void do_idle();
    void do_stop();
    void do_timeout();
    void do_draw_outlet();

    rtos::MessageQueue<State, 2> m_mq;
    State m_state = State::IDLE;
};

inline utils::Object<DrawTask> drawTask;

}


#endif
